package com.runa.monitor.platinterface.extend.hmy;

import com.alibaba.fastjson.JSON;
import com.runa.persistence.DateUtil;
import lombok.Data;
import org.springframework.http.HttpMethod;
import org.springframework.util.Base64Utils;
import org.springframework.util.DigestUtils;

/**
 * 2024/10/18 10:24
 * zhangYB
 */
@Data
public class HmyValveWorkModeRequest extends HmyRequest {

    /**
     * 132：流量平衡模式(可以设置 0-100 间的任意开度)
     * 131：室温模式(根据设定的温度，改变阀门开度)
     * 130：回水模式(根据设定的温度，改变阀门开度)
     * 129：通断模式(只能设置 0 或 100 两种开度)
     */
    private String mode;


    public HmyValveWorkModeRequest(Long msgId, String nodeId, String expiredDate, String mode) {
        super(msgId, nodeId, expiredDate);
        this.mode = mode;
    }

    public static void main(String[] args) {
        HmyValveWorkModeRequest requestBody = new HmyValveWorkModeRequest(1L, "19511240505895", null, "132");
        System.out.println(JSON.toJSONString(requestBody));


        String timestamp = DateUtil.nowToString("yyyyMMddHH24mmss");
        String accessToken = DigestUtils.md5DigestAsHex(("TAIYUANTAIGUGONGRE" + "tytggr2025" + timestamp).getBytes());
        String authorization = Base64Utils.encodeToString(("TAIYUANTAIGUGONGRE" + ":" + timestamp).getBytes());
        System.out.println("accessToken: " + accessToken);
        System.out.println("authorization: " + authorization);

        HmyValveService hmyValveService = new HmyValveService();
        HmyResponse request = hmyValveService.request("http://222.189.34.50:21641/api/v1/data/Vx/setWorkModeApi", HttpMethod.POST, requestBody);


    }
}
